package edu.neu.swc.commerce.service.communication.hystrix;

import edu.neu.swc.commerce.service.communication.AuthorityFeignClient;
import edu.neu.swc.commerce.vo.JwtToken;
import edu.neu.swc.commerce.vo.UsernameAndPassword;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * <h1>open feign 集成Hystrix的另一种模式</h1>
 */
@Slf4j
@Component
public class AuthorityFeignClientFallbackFactory
        implements FallbackFactory<AuthorityFeignClient> {
    @Override
    public AuthorityFeignClient create(Throwable throwable) {

        log.warn("authority feign client get token by feign request error " +
                "(Hystrix FallbackFactory):[{}]", throwable.getMessage(), throwable);
        return usernameAndPassword -> new JwtToken("WangYFactory");
    }
}
